public class RemoveNthFromEnd {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dump = new ListNode(-1);
        dump.next = head;
        ListNode fast = dump, slow = dump;
        while (n-- > 0) {
            fast = fast.next;
        }
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next;
        }
        ListNode pre = slow;
        ListNode cur = slow.next;
        ListNode next = slow.next.next;
        pre.next = next;
        cur.next = null;
        return dump.next;
    }

}
